<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  >
      <el-form-item label="课题名称" prop="issueName" >
        <el-input
          v-model="queryParams.issueName"
          placeholder="请输入课题名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="栏目" prop="viewsTimes" >
        <el-input
          v-model="queryParams.contentColumn"
          placeholder="请输入栏目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="课题类别" prop="topicCategory" >
       <!-- <el-input
          v-model="queryParams.topicCategory"
          placeholder="请输入课题类别"
          clearable
          @keyup.enter.native="handleQuery"
        />-->
        <el-select
          v-model="queryParams.topicCategory"
          placeholder="请选择课题类别"
          clearable
        >
          <el-option
            v-for="dict in dict.type.kexue"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="图片路径" prop="pictureUrl">
        <el-input
          v-model="queryParams.pictureUrl"
          placeholder="请输入图片路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="材料路径" prop="sourcesUrl">
        <el-input
          v-model="queryParams.sourcesUrl"
          placeholder="请输入材料路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择科学研究发布时间">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="参与人员" prop="participants"  >
         <el-input
           v-model="queryParams.participants"
           placeholder="请输入科学研究参与人员"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
       <el-form-item label="浏览次数" prop="viewsTimes" >
         <el-input
           v-model="queryParams.viewsTimes"
           placeholder="请输入浏览次数"
           clearable
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>-->
      <!--<el-form-item label="创建者" prop="createBy" v-show="showSearch">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime" v-show="showSearch">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy" v-show="showSearch">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime" v-show="showSearch">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>-->
      <br/>
      <div style="text-align:right;">

        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

      </div>
      <br/>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          icon="el-icon-plus"
          @click="handleAdd"
          v-hasPermi="['yzx:tb:foundations:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          icon="el-icon-delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yzx:tb:foundations:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yzx:tb:foundations:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contentList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号"  width="55" :index="indexMethod" align="center"/>
      <!--<el-table-column label="标题" align="center" prop="noticeTitle" />
      <el-table-column label="内容" align="center" prop="noticeContent" />
      <el-table-column label="状态" align="center" prop="noticeStatus" />
      <el-table-column label="栏目" align="center" prop="contentColumn" />-->
      <el-table-column label="课题名称" align="center" prop="issueName" />
      <el-table-column label="课题类别" align="center" prop="topicCategory" >
       <!-- <el-select
          v-model="queryParams.topicCategory"
          placeholder="请选择课题类别"
          clearable
        >
          <el-option
            v-for="dict in dict.type.kexue"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>-->
        <template slot-scope="scope">
          <dict-tag :options="dict.type.kexue" :value="scope.row.topicCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="课题年度" align="center" prop="projectYear" />
      <el-table-column label="承研单位" align="center" prop="researchUnit" />
      <el-table-column label="课题负责人" align="center" prop="projectLeader" />
      <el-table-column label="课题状态" align="center" prop="issueStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.issueStatus==0">申请</span>
          <span v-if="scope.row.issueStatus==1">在研</span>
          <span v-if="scope.row.issueStatus==2">结题</span>
        </template>

      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"

            @click="handleUpdate(scope.row)"
            v-hasPermi="['yzx:tb:foundations:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handleDelete(scope.row)"
            v-hasPermi="['yzx:tb:foundations:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"

            @click="handlelook(scope.row)"

          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改内容发布对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-container>
          <!-- <el-header>
             <el-divider content-position="left">
                <p style="color: #00afff; font-size: 20px;">纪检监察基本信息
               </p>
             </el-divider>
           </el-header>-->
          <el-main>
            <el-row>
              <el-col span="12" style="display: none">
                <el-form-item label="类型" prop="noticeType">
                  <el-input v-model="form.noticeType='8'"></el-input>

                </el-form-item>
              </el-col>
            <!--  <el-col span="8">
                <el-form-item label="栏目" prop="contentColumn">
                  <el-select
                    v-model="form.contentColumn"
                    placeholder="请输入栏目名"
                    clearable
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.yh_notice_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"/>
                  </el-select>

                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="标题" prop="noticeTitle">
                  <el-input v-model="form.noticeTitle" placeholder="请输入标题" />
                </el-form-item>
              </el-col>-->
              <el-col span="8">
                <el-form-item label="课题名称" prop="issueName">
                  <el-input v-model="form.issueName" placeholder="请输入课题名称" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="课题类别" prop="topicCategory">
               <!--   <el-input v-model="form.topicCategory" placeholder="请输入课题类别" />-->
                  <el-select
                    v-model="form.topicCategory"
                    placeholder="请选择课题类别"
                    clearable
                  >
                    <el-option
                      v-for="dict in dict.type.kexue"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>



                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="课题年度" prop="projectYear">
                  <el-input v-model="form.projectYear" placeholder="请输入课题年度" />
                </el-form-item>
              </el-col>
            </el-row>


            <el-row>
              <el-form-item label="内容">
                <editor v-model="form.noticeContent" :min-height="192" placeholder="请输入内容"/>
              </el-form-item>
             <!-- <el-form-item label="材料路径" prop="sourcesUrl">
                <file-upload v-model="form.sourcesUrl"/>
              </el-form-item>
-->

            </el-row>
            <el-row>
              <el-col span="8">
                <el-form-item label="课题负责人" prop="projectLeader">
                  <el-input v-model="form.projectLeader" placeholder="请输入课题负责人" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="课题成员" prop="subjectMembers">
                  <el-input v-model="form.subjectMembers" placeholder="请输入课题成员" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="经费类算" prop="fundingCategories">
                  <el-input v-model="form.fundingCategories" placeholder="请输入经费类算" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col span="8">
                <el-form-item label="进展情况" prop="progress">
                  <el-input v-model="form.progress" placeholder="请输入进展情况" />
                </el-form-item>
              </el-col>
            <!--  <el-col span="8">
                <el-form-item label="进度周期预警" prop="progressPeriod">
                  <el-input v-model="form.progressPeriod" placeholder="请输入进度周期预警" />
                </el-form-item>
              </el-col>-->
              <el-col span="8">
                <el-form-item label="承研单位" prop="researchUnit">
                  <el-input v-model="form.researchUnit" placeholder="请输入承研单位" />
                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="课题状态" prop="issueStatus">

                  <el-select v-model="form.issueStatus" placeholder="请选择" >
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">

                    </el-option>
                  </el-select>


                </el-form-item>
              </el-col>
            </el-row>




             <!-- <el-col span="8">
                <el-form-item label="图片路径" prop="pictureUrl">
                  <image-upload v-model="form.pictureUrl"/>

                </el-form-item>
              </el-col>
              <el-col span="8">
                <el-form-item label="附件" prop="annex">
                  <file-upload v-model="form.annex"/>
                </el-form-item>
              </el-col>-->



            <el-row>

            <!--  <el-col span="8">
                <el-form-item label="状态" prop="noticeStatus" >

                  <el-select
                    v-model="form.noticeStatus"
                    placeholder="状态"
                    clearable
                    style="width: 100%"
                  >
                    <el-option
                      v-for="dict in dict.type.yh_notice_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"/>
                  </el-select>
                </el-form-item>
              </el-col>-->
            </el-row>

          </el-main>
        </el-container>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<style>
.ql-toolbar.ql-snow {
  text-align: left;
  border: 1px solid #ccc;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  padding: 8px;
  /* float: none; */
}
.el-header, .el-footer {
  background-color: #FFFFFF;
  color: #333;
  text-align: left;
  line-height: 60px;
  font-style: oblique;

}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #FFFFFF;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

/*对话框标题样式*/
.el-dialog__title{
  /*color: #1ab394;*/
  font-weight: bold;
  font-size: 25px;
}
</style>
<script>
import { listContent, getContent, delContent, addContent, updateContent } from "@/api/module/yzx/tb/technicalbasis";
import watermark from "watermark-dom";

export default {
  name: "Content",
  dicts:['yh_notice_type','yh_notice_status','kexue'],
  mounted() {
    watermark.load({ watermark_txt: '  '   });
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 内容发布表格数据
      contentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeType: "8",
        noticeTitle: null,
        noticeContent: null,
        noticeStatus: null,
        pictureUrl: null,
        sourcesUrl: null,
        releaseTime: null,
        participants: null,
        viewsTimes: null,
        contentColumn: null,
        haveExperience: null,
        experienceContent: null,
        fileNum: null,
        userId: null,
        deptId: null,
        noticeId: null,
        issueName: null,
        topicCategory: null,
        projectYear: null,
        researchUnit: null,
        projectLeader: null,
        subjectMembers: null,
        fundingCategories: null,
        annex: null,
        progress: null,
        progressPeriod: null,
        issueStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,

      },
      // 表单参数
      form: {},
      options: [{
        value: '0',
        label: '申请'
      }, {
        value: '1',
        label: '在研'
      },{
      value: '2',
        label: '结题'
    }],
      // 表单校验
      rules: {
        /*contentColumn: [
          { required: true, message: "栏目不能为空", trigger: "blur" },
        ],*/
        projectYear: [
          { required: true, message: "课题年度不能为空", trigger: "blur" },
        ],
        issueName: [
          { required: true, message: "课题名称不能为空", trigger: "blur" },
        ],
        topicCategory: [
          { required: true, message: "课题类别不能为空", trigger: "blur" },
        ],
        noticeStatus: [
          { required: true, message: "状态不能为空", trigger: "blur" },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    indexMethod(index) {
      index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      return index
    },
    /** 查询内容发布列表 */
    getList() {
      this.loading = true;

      listContent(this.queryParams).then(response => {

        this.contentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        noticeType: '8',
        noticeTitle: null,
        noticeContent: null,
        noticeStatus: null,
        pictureUrl: null,
        contentColumn:null,
        sourcesUrl: null,
        releaseTime: null,
        participants: null,
        viewsTimes: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.i = selection.map(item => item.noticeTitle)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "科学研究";
      //this.$tab.openPage("用户管理","/monitor/online");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改科学研究";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContent(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContent(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handlelook(row) {
      const id = row.id;
      // const tableName = row.tableName || this.tableNames[0];
      const params = {pageNum: this.queryParams.pageNum};

      this.$router.push({path: "/yewu/tbtoxiangqing", query: {id}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const i = row.noticeTitle || this.i;
      this.$modal.confirm('是否确认删除标题为"' + i + '"的数据项？').then(function() {
        return delContent(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yzx/tb/foundations/export', {
        ...this.queryParams
      }, `content_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
